<template>
  <div id='GoodListItem' @click="jumpdetail" v-if="Object.keys(gooditem).length !==0">
    <img :src="showimg" alt="" @load="goodimgload">
    <div>{{gooditem.title}}</div>
  </div>
</template>

<script>
  export default {
    name: 'GoodListItem',
    data() {
      return {}
    },
    props: {
      gooditem: {
        type: Object,
        default() {

        }
      }
    },
    computed: {
      showimg() {
        return this.gooditem.image || this.gooditem.show.img
      }
    },
    methods: {
      // 1.各自监听各自组件的图片加载
      // goodimgload() {
      //   if (this.$route.path.indexOf('/home')) {
      //     this.$bus.$emit('goodimgload')
      //   } else if (this.$route.path.indexOf('/detail')) {
      //     this.$bus.$emit('detailimgload')
      //   }
      // },
      goodimgload() {
        this.$bus.$emit('goodimgload')
      },
      jumpdetail() {
        this.$router.push('/detail/' + this.gooditem.iid)
      }
    },
  }
</script>

<style scoped>
  #GoodListItem {
    width: 48%;
  }

  #GoodListItem img {
    width: 100%;
  }
</style>